import 'package:flutter/material.dart';
import 'package:flutter_douban/config/app_colors.dart';
import 'package:flutter_douban/main_page/store/page/store_shop_page.dart';
import 'package:flutter_douban/model/store_category_model.dart';

class ProductBottowCell extends StatefulWidget {
  final StoreCategoryModel model;
  const ProductBottowCell({Key? key,required this.model}) : super(key: key);

  @override
  _ProductBottowCellState createState() => _ProductBottowCellState();
}

class _ProductBottowCellState extends State<ProductBottowCell> {

  @override
  Widget build(BuildContext context) {

    List<Widget> rowList = [];
    widget.model.ss!.forEach((element) {
      rowList.add(
        RichText(
          text: TextSpan(
            text: element['t']+"   ",
            style: TextStyle(
              fontSize: 13,
              color: Colors.black45,
              decorationColor: Colors.black45,
            ),
            children: [
              TextSpan(
                text: element['s'],
                style: TextStyle(fontSize: 13, color: Colors.black),
              ),
            ],
          ),
        ),
      );
    });

    return Container(
      padding: EdgeInsets.only(left: 20, right: 20,bottom: 20),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text('店铺信息',
              style: TextStyle(
                  fontSize: 20,
                  color: AppColors.black,
                  fontWeight: FontWeight.bold)),
          SizedBox(height: 10,),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              _avatar(),
              _btn(),
            ],
          ),
          SizedBox(height: 10,),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: rowList,
          ),
        ],
      ),
    );
  }

  /// 头像
  Widget _avatar() {
    return Row(
      children: [
        Container(
          width: 34,
          height: 34,
          decoration: BoxDecoration(
            color: AppColors.page,
            borderRadius: BorderRadius.circular(17),
          ),
          child: ClipOval(
            child: FadeInImage.assetNetwork(
              placeholder: 'assets/images/common/lazy-1.png',
              image: widget.model.l!,
              fit: BoxFit.cover,
            ),
          ),
        ),
        SizedBox(
          width: 8,
        ),
        _centerview(),
      ],
    );
  }

  /// 中间内容
  Widget _centerview() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(
          widget.model.n!,
          maxLines: 1,
          overflow: TextOverflow.ellipsis,
          style: TextStyle(
            fontSize: 13,
            fontWeight: FontWeight.bold,
            color: AppColors.black,
          ),
        ),
        SizedBox(
          height: 3,
        ),
        Text(
          widget.model.sfi!,
          overflow: TextOverflow.ellipsis,
          style: TextStyle(
            fontSize: 12,
            color: AppColors.qianTextColor,
          ),
        ),
      ],
    );
  }

  /// 好评按钮
  Widget _btn() {
    return InkWell(
      child: Container(
        alignment: Alignment.center,
        height: 30,
        width: 70,
        decoration: BoxDecoration(
          color: AppColors.yellow,
          borderRadius: BorderRadius.circular(15),
        ),
        child: Text(
          '进店逛逛',
          style: TextStyle(
            color: AppColors.black,
            fontSize: 13,
          ),
        ),
      ),
      onTap: (){
        Navigator.of(context).push(MaterialPageRoute(builder: (_) {
          return StoreShopPage();
        }));
      },
    );
  }
}
